//
//  SEDepartmentAPI.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/25.
//

import Moya

enum SECommonPikcerAPI {
    case listOfAllDepartments
    case listOfHospitals(provinceId: String, cityId: String, regionId: String)
    case listOfJobTitles
    case usageOfPrescriptionDrug(mark: String)
}

extension SECommonPikcerAPI: TargetType {
    var baseURL: URL { URL(string: SEApiManager.baseUrl)! }
    
    var path: String {
        switch self {
        case .listOfAllDepartments,
             .usageOfPrescriptionDrug: return "/ng/newfuture-org/dict/listByMark"
        case .listOfHospitals: return "/ng/newfuture-org/org/hospital/list"
        case .listOfJobTitles: return "/smarteye/smarteye-base/basic/dict/getList"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .listOfAllDepartments,
             .listOfHospitals,
             .listOfJobTitles,
             .usageOfPrescriptionDrug:
            return .get
        }
    }
    
    var sampleData: Data { "".data(using: .utf8)! }
    
    var task: Task {
        SELog("\(path) - \(parameters)")
        switch self {
        case .listOfAllDepartments,
             .listOfHospitals,
             .listOfJobTitles,
             .usageOfPrescriptionDrug:
            return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
        }
    }
    
    var headers: [String : String]? { SEApiManager.headers }
    
    private var parameters: [String: Any] {
        switch self {
        case .listOfAllDepartments:
            return ["mark": "org_dept"]
        case let .listOfHospitals(provinceId, cityId, _):
            return ["provinceId": provinceId,
                    "cityId": cityId,
                    "regionId": ""]
        case .listOfJobTitles:
            return ["category": "doc_job_title"]
        case .usageOfPrescriptionDrug(let mark):
            return ["mark": mark]
        }
    }
}
